/* ************************************************************************

   Copyright:

   License:

   Authors: SALMON Charles

************************************************************************ */

/* ************************************************************************

************************************************************************ */

/**
 * Handles properties that are dynamically setup by the server
 */
qx.Class.define("bip.DynamicProperties", 
{
	extend: qx.core.Object,
	
	type: "singleton",
	
	/*
	*****************************************************************************
	 PROPERTIES
	*****************************************************************************
	*/  
	properties :
	{
		/**
		 * Role assigned to user: "user" or "author"
		 */
		"userRole": 
		{
			check:"String",
			nullable:true	
		},
		
		/**
		 * Url to access to JSON service
		 */
		"jsonUrl": 
		{
			check:"String",
			nullable:true	
		}
		
	},
	
	/*
	*****************************************************************************
	 CONSTRUCTOR
	*****************************************************************************
	*/
	
	/**
	 * Setup properties values from filtered ones
	 */	
 	construct: function()
	{
		this.base(arguments);
		
		// The following will be replaced by real values
		var isBipUser = "$[IS_BIP_USER]$";
		var isBipAuthor = "$[IS_BIP_AUTHOR]$";
		var jsonUrl = "$[JSON-RPC-URI]$";
		
		// User role
		if (isBipUser == "$["+"IS_BIP_USER"+"]$") {
			this.error("Property 'IS_BIP_USER' was not filtered by server !");
		} 
		else if (isBipAuthor == "$["+"IS_BIP_AUTHOR"+"]$") {
			this.error("Property 'IS_BIP_AUTHOR' was not filtered by server !");
		}
		else {
			if (eval(isBipUser)) {this.setUserRole("user");}
			else if (eval(isBipAuthor)) {this.setUserRole("author");}
			else {
				this.error("Undefined user role !");
			}
		}
		
		// JSON
		if (jsonUrl == "$["+"JSON-RPC-URI"+"]$") {
			this.error("Property 'JSON-RPC-URI' was not filtered by server !");
		} else {
			this.setJsonUrl(jsonUrl);
		}
		
	},
	
	/*
	*****************************************************************************
	 MEMBERS
	*****************************************************************************
	*/	
	members : {
		
	}
});